package com.acane.instagram.feature.common

import android.util.Log
import com.acane.instagram.core.model.UserInfo

// SessionManager.kt
object SessionManager {
//    private lateinit var sharedPreferences: SharedPreferences
//    private const val PREF_NAME = "InstagramPrefs"
//    private const val KEY_USER = "user"
//    private const val KEY_SESSION_ID = "sessionId"
//    private const val KEY_JWT_TOKEN = "jwtToken"

//    fun init(context: Context) {
//        if (!::sharedPreferences.isInitialized) {
//            sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
//        }
//    }
//
//    fun login(user: UserInfo, sessionId: String, token: String) {
//        sharedPreferences.edit().apply {
//            putString(KEY_USER, user.toString())
//            putString(KEY_SESSION_ID, sessionId)
//            putString(KEY_JWT_TOKEN, token)
//            apply()
//        }
//    }
//
//    fun getJwtToken(): String? {
//        if (!::sharedPreferences.isInitialized) {
//            throw IllegalStateException("SessionManager has not been initialized. Call init(context) first.")
//        }
//        return sharedPreferences.getString(KEY_JWT_TOKEN, null)
//    }
//
//    fun clearSession() {
//        if (!::sharedPreferences.isInitialized) {
//            throw IllegalStateException("SessionManager has not been initialized. Call init(context) first.")
//        }
//        sharedPreferences.edit().clear().apply()
//    }

    private var _currentUser: UserInfo? = null
    private var _loggedAccountList: MutableList<UserInfo> = mutableListOf()
    var _sessionId: String? = null

    val currentUser: UserInfo?
        get() = _currentUser



    val loggedAccountList: MutableList<UserInfo>
        get() = _loggedAccountList

    fun login(user: UserInfo, sessionId: String) {
        _currentUser = user
        _sessionId = sessionId
        Log.d("SessionManager", "login: $sessionId")
        if (!_loggedAccountList.contains(user)) {
            _loggedAccountList.add(user)
        }
    }

    fun logout() {
        _currentUser = null
    }
}